import api from '@/api'

// state
const state = {
    data: {
        classifis: []
    },
    ui: {}
}

// getters
const getters = {
    classifis: state => state.data.classifis,
    departOperations: state => state.ui.operations
}

// actions
const actions = {

    getKnowledge({ commit }, params) {
        api.getKnowledge({
            loading: true,
            data: params,
            method: 'get',
            success: (res) => {
                console.log(res)
                let classifis = res
                commit('SETKNOWLEDGE', { classifis })
            }
        })
    },

    editKnowledge({ dispatch }, params) {
        api.editKnowledge({
            method: 'put',
            data: params,
            success: (res) => {
                dispatch('getKnowledge')
            }
        })
    },

    removeKnowledge({ dispatch }, params) {
        api.removeKnowledge({
            method: 'delete',
            data: params,
            success: (res) => {
                dispatch('getKnowledge')
            }
        })
    }

}

// mutations
const mutations = {

    SETKNOWLEDGE(state, payload) {
        state.data.classifis = payload.classifis
    }
}

export default {
    state,
    getters,
    actions,
    mutations
}